from wtforms import Form
from wtforms.fields import StringField, PasswordField, IntegerField
from wtforms.validators import DataRequired, Length, EqualTo, ValidationError
from .base_validate import ValidateMixin
from app.constant import StoreStatus


class StorePostValidate(Form, ValidateMixin):

    mobile = StringField(validators=[DataRequired(message='手机号不能为空')])
    user_name = StringField(validators=[DataRequired(message='姓名不能为空'), Length(min=1, max=10, message='姓名长度需小于10')])
    store_name = StringField(validators=[DataRequired(message='商铺名不能为空'), Length(min=3, max=12, message='商铺名需大于3小于12')])
    img_shopkeeper_id_card_id = IntegerField(validators=[DataRequired('身份证图片id不能为空')])
    img_logo_id = IntegerField(validators=[DataRequired('logo id不能为空')])
    img_business_license_id = IntegerField(validators=[DataRequired('营业执照id不能为空')])

    address = StringField(validators=[DataRequired(message='地址不能为空'), Length(min=5, max=250, message='地址长度必须大于5小于250')])
    summary = StringField(validators=[DataRequired(message='摘要不能为空'), Length(min=5, max=250, message='地址长度必须大于5小于250')])

    def validate_mobile(self, field):
        self.check_mobile(field)




class StoreStatusPutValidate(Form):
    store_id = IntegerField(validators=[DataRequired('商铺 id不能为空')])
    status = IntegerField(validators=[DataRequired('商铺 状态不能为空')])

    def validate_status(self, field):
        status = field._value()
        if status not in StoreStatus.all:
            raise ValidationError(u'status是不合法的数字')